package com.nuc.zyt;

import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;
public class Student {
    Integer id;
    String name;
    String number;
    int math;
    int chinese;
    int English;
    int sum;

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", number='" + number + '\'' +
                ", math=" + math +
                ", chinese=" + chinese +
                ", English=" + English +
                ", sum=" + sum +
                '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getNumber() {
        return number;
    }
    public void setNumber(String number) {
        this.number = number;
    }
    public int getMath() {
        return math;
    }
    public void setMath(int math) {
        this.math = math;
    }
    public int getChinese() {
        return chinese;
    }
    public void setChinese(int chinese) {
        this.chinese = chinese;
    }
    public int getEnglish() {
        return English;
    }
    public void setEnglish(int english) {
        English = english;
    }
    public int getSum() {
        return sum;
    }
    public void setSum(int sum) {
        this.sum = sum;
    }

    public static void main(String[] args) {
        HashMap<Integer,Student> hashMap = new HashMap<>();
        Scanner sc = new Scanner(System.in);
        while (true)
        {
            printview();
            System.out.println("请输入您要实现的的功能：");
            int data = sc.nextInt();
            switch (data)
            {
                case 1 : setStudent(hashMap);break;
                case 2 : delete(hashMap);break;
                case 3 : Change(hashMap);break;

                case 4 :print01(hashMap);break;
                case 5 : System.out.println("欢迎下次使用！");System.exit(1);
            }
        }

    }
    public static void printview()
    {
        System.out.println("---欢迎来到学生管理系统！----");
        System.out.println("---请选择以下对应的功能------");
        System.out.println("------1.添加学生信息--------");
        System.out.println("------2.删除学生信息--------");
        System.out.println("------3.修改学生信息--------");
        System.out.println("------4.查看所有学生信息-----");
        System.out.println("------5.退出管理系统--------");
    }


    //添加学生信息
    public static void setStudent(HashMap<Integer,Student> hs)
    {
        Scanner sc = new Scanner(System.in);
        Student s = new Student();
        System.out.println("输入id");
        Integer id = sc.nextInt();
        s.setId(id);
        System.out.println("请输入学生的学号：");
        String number  =sc.next();
        s.setNumber(number);
        System.out.println("请输入学生的姓名：");
        String name = sc.next();
        s.setName(name);
        System.out.println("请输入学生的语文成绩：");
        Integer yuwen = sc.nextInt();
        s.setChinese(yuwen);
        System.out.println("请输入学生的数学成绩：");
        Integer shuxue = sc.nextInt();
        s.setMath(shuxue);
        System.out.println("请输入学生英语成绩：");
        Integer yiyu = sc.nextInt();
        s.setEnglish(yiyu);
        System.out.println("请输入学生的总成绩：");
        Integer zcj = sc.nextInt();
        s.setSum(zcj);

        // 添加学生到map
        hs.put(id,s);

        System.out.println("添加成功！");

    }

    //删除学生信息
    @SuppressWarnings({ "unlikely-arg-type", "resource" })
    public static void delete(HashMap<Integer,Student> hs)
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您要删除学生的姓名：");
        String name= sc.nextLine();
        if(hs.get(name)!=null)
        {
            hs.remove(name);
            System.out.println("删除成功！");
        }
        else
        {
            System.out.println("此学生不存在！");
        }
    }

    //显示单个学生信息
    public static void print01(HashMap<Integer,Student> hs)
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您要查询的学生的id：");
        Integer id = sc.nextInt();
        if (hs.get(id)!=null)
        {
            Student s = hs.get(id);
            System.out.println("查询成功！");
            System.out.println(s);
            System.out.println(" 姓名："+s.getName()+" 学号："+s.getNumber()+" 语文成绩："+s.getChinese()+" 数学成绩："+s.getMath()+" 英语成绩:"+s.getEnglish()+" 总成绩:"+s.getSum());
        }
        else
        {
            System.out.println("该学生不存在！");
        }
    }

    //显示所有学生信息
    public static void print02(HashMap<Integer,Student> hs)
    {
        System.out.println("所有学生信息如下：");
        Set<Integer> set = hs.keySet();

        for (Integer i :set)
        {
            Student s = hs.get(i);
            System.out.println(" 姓名："+s.getName()+" 学号："+s.getNumber()+" 语文成绩："+s.getChinese()+" 数学成绩："+s.getMath()+" 英语成绩:"+s.getEnglish()+" 总成绩:"+s.getSum());
        }

    }
    //修改学生信息
    public static void Change(HashMap<Integer,Student> hs)
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你要修改的学生学号：");
        String number = sc.nextLine();

        if (hs.get(number)!=null)
        {
            Scanner sc1 = new Scanner(System.in);
            Student s = hs.get(number);
            System.out.println("请输入您要修改的学生的具体信息：(姓名，学号，语文成绩，数学成绩，英语成绩，总成绩。)");
            String data = sc1.nextLine();
            if (data.equals("学号"))
            {
                System.out.println("请输入您要修改的学号：");
                String number1 = sc1.nextLine();
                s.setNumber(number1);
                System.out.println("修改完成！");
            }

            else if (data.equals("姓名"))
            {
                System.out.println("请输入您要修改的姓名：");
                String name= sc1.nextLine();
                s.setName(name);
                System.out.println("修改完成！");
            }

            else if (data.equals("语文成绩"))
            {
                System.out.println("请输入您要修改的语文成绩：");
                int yuwen = sc1.nextInt();
                s.setChinese(yuwen);
                System.out.println("修改完成！");
            }

            else if (data.equals("数学成绩"))
            {
                System.out.println("请输入您要修改的数学成绩：");
                int shuXue = sc1.nextInt();
                s.setMath(shuXue);
                System.out.println("修改完成！");
            }
            else if (data.equals("英语成绩"))
            {
                System.out.println("请输入您要修改的英语成绩：");
                int yiyu= sc1.nextInt();
                s.setEnglish(yiyu);
                System.out.println("修改完成！");
            }
            else if (data.equals("总成绩"))
            {
                System.out.println("请输入您要修改的总成绩：");
                int zcj = sc1.nextInt();
                s.setSum(zcj);
                System.out.println("修改完成！");
            }

        }
    }
}